<?php
require_once ("edit_secure_area.php");
class Edit_employees extends Secure_area 
{
	function __construct()
	{
		parent::__construct('edit_employees');
	}
	
	function index()
	{
	}
	
	function edit($id = -1)
	{
		$data['person_info']=$this->Edit_employee->get_logged_in_employee_info();
		$this->load->view("employees/form_update",$data);
	}
	
		
	function save()
	{
		$person_info = $this->Edit_employee->get_logged_in_employee_info();
		$employee_id = $person_info->person_id;
		//echo $employee_id;
	
		$person_data = array(
		'first_name'=>$this->input->post('first_name'),
		'last_name'=>$this->input->post('last_name'),
		'email'=>$this->input->post('email'),
		'phone_number'=>$this->input->post('phone_number'),
		'address_1'=>$this->input->post('address_1'),
		'address_2'=>$this->input->post('address_2'),
		'city'=>$this->input->post('city'),
		'state'=>$this->input->post('state'),
		'zip'=>'',
		'country'=>$this->input->post('country'),
		'comments'=>$this->input->post('comments')
		);
		
		//Password has been changed OR first time password set
		if($this->input->post('password')!='')
		{
			$employee_data=array(
			'username'=>$this->input->post('username'),
			'password'=>md5($this->input->post('password'))
			);
		}
		else //Password not changed
		{
			$employee_data=array('username'=>$this->input->post('username'));
		}
		
		if($this->Edit_employee->save_update($person_data,$employee_data,$permission_data,$employee_id))
		{
			echo json_encode(array('success'=>true,'message'=>$this->lang->line('employees_successful_updating').' '.
			$person_data['first_name'].' '.$person_data['last_name'],'person_id'=>$employee_id));
		}
		else//failure
		{	
			echo json_encode(array('success'=>false,'message'=>$this->lang->line('employees_error_adding_updating').' '.
			$person_data['first_name'].' '.$person_data['last_name'],'person_id'=>-1));
		}
	}
}
?>